<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/include/head.jsp"%>
<head>
<title>Insert title here</title>
<style type="text/css">
.item-top{
	margin-top: 15px;
}
.item-right{
	margin-right: 30px;
}
</style>
</head>
<body>
	<form class="layui-form" action="">
		<div class="layui-form-item item-top">
			<label class="layui-form-label">账号</label>
			<div class="layui-input-block item-right">
				<input type="text" name="username" required lay-verify="required"
					placeholder="请输入标题" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-inline">
				<input type="password" name="password" required lay-verify="required" 
					placeholder="请输入密码" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-form-mid layui-word-aux"><!-- 提示语 --></div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="login-form">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
	
	<script>
		layui.use('form', function() {
			var form = layui.form;

			//监听提交
			form.on('submit(login-form)', function(data) {
				//console.log(data.field);
				var link = "${ctx}/sys/login";
				$.ajax({
					type: "post",
					url: link,					
					data: {"username": data.field.username,"password": data.field.password},
					success: function(data) {
						console.log(data);
						if(data.code == 0){
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index); // 关闭父页面
							//location.href='${ctx}/sys/toChatHome?userId=' + data.userId
						}else{
							layer.msg("登录失败", {icon: 5});
						}
					}
				});
				
				//layer.msg(JSON.stringify(data.field));
				return false;
			});
		});
		$(document).ready(function() {
		})
	</script>
</body>
</html>